textview: Use device timestamps for obscured cursors
authorMatthias Clasen <mclasen@redhat.com>
Fri, 26 Mar 2021 02:42:10 +0000 (22:42 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 26 Mar 2021 14:30:33 +0000 (10:30 -0400)
Stash away the device timestamp when obscuring
the pointer, and compare it when we decice whether
to unobscure it. This fixes a problem where synthetic
motion events would make the cursor reappear
prematurely.

Fixes: #3792
gtk/gtktextview.c

index 13b0e677522f477bacb08f0afb2f38f59dca6477..33c40d3555abfacbfa3ec37b6ead30d33910cdb3 100644 (file)
@@ -259,8 +259,12 @@ struct _GtkTextViewPrivate
   int bottom_padding;
 
   int indent;
+
+  guint32 obscured_cursor_timestamp;
+
   gint64 handle_place_time;
   PangoTabArray *tabs;
+
   guint editable : 1;
 
   guint overwrite_mode : 1;
@@ -5048,18 +5052,36 @@ gtk_text_view_state_flags_changed (GtkWidget     *widget,
 static void
 gtk_text_view_obscure_mouse_cursor (GtkTextView *text_view)
 {
+  GdkDisplay *display;
+  GdkSeat *seat;
+  GdkDevice *device;
+
   if (text_view->priv->mouse_cursor_obscured)
     return;
 
   gtk_widget_set_cursor_from_name (GTK_WIDGET (text_view), "none");
 
+  display = gtk_widget_get_display (GTK_WIDGET (text_view));
+  seat = gdk_display_get_default_seat (display);
+  device = gdk_seat_get_pointer (seat);
+
+  text_view->priv->obscured_cursor_timestamp = gdk_device_get_timestamp (device);
   text_view->priv->mouse_cursor_obscured = TRUE;
 }
 
 static void
 gtk_text_view_unobscure_mouse_cursor (GtkTextView *text_view)
 {
-  if (text_view->priv->mouse_cursor_obscured)
+  GdkDisplay *display;
+  GdkSeat *seat;
+  GdkDevice *device;
+
+  display = gtk_widget_get_display (GTK_WIDGET (text_view));
+  seat = gdk_display_get_default_seat (display);
+  device = gdk_seat_get_pointer (seat);
+
+  if (text_view->priv->mouse_cursor_obscured &&
+      gdk_device_get_timestamp (device) != text_view->priv->obscured_cursor_timestamp)
     {
       gtk_widget_set_cursor_from_name (GTK_WIDGET (text_view), "text");
       text_view->priv->mouse_cursor_obscured = FALSE;